<!DOCTYPE html>
<html lang="en">
<head>
<title>Unicorn Admin</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/static/css/bootstrap.min.css" />
<link rel="stylesheet" href="/static/css/bootstrap-responsive.min.css" />
<link rel="stylesheet" href="/static/css/uniform.css" />
<link rel="stylesheet" href="/static/css/select2.css" />
<link rel="stylesheet" href="/static/css/datepicker.css" />
<link rel="stylesheet" href="/static/css/unicorn.main.css" />
<link rel="stylesheet" href="/static/css/unicorn.grey.css"
	class="skin-color" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/cityJSON.txt"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						
						//读取json数组
						var jsonAry = eval(json);
						//遍历获取省份并加载列表
						for (var i = 0; i < jsonAry.length; i++) {
							var provinceName = jsonAry[i].name;
							$('.provinces').append(
									"<option>" + provinceName + "</option>");
						};
						var proJson;
						var cityAry
						if('${orgInfo}' == ''){
							$("#orgH1").html('添加机构');
							//获取北京json						
							proJson = jsonAry[0];
							cityAry= proJson["北京市"];
						}else{
							$("#orgH1").html('修改机构');
							for (var i = 0; i < jsonAry.length; i++) {
								//遍历json对象
								for (var key in jsonAry[i]) {
									if (key == '${orgInfo.province}') {
										cityAry = jsonAry[i][key];
										break;
									};
								};
							};
						}
						for (var i = 0; i < cityAry.length; i++) {
							$('#selCity').append("<option>"+ cityAry[i]+ "</option>");
						};
						if ('${orgInfo}' == '') {
							$("#submitbt").attr('disabled', true);
						} else {
							$('#nameSpan').html('');
							$('#addressSpan').html('');
							$('#telSpan').html('');
							//修改页面表单赋值
							$("[name='province']").val('${orgInfo.province}');
							$("[name='city']").val('${orgInfo.city}');
							$("[name='contactName']").val('${orgInfo.contactName}');
							$("[name='important']").val('${orgInfo.important}');
							$("[name='orgKindName']").val('${orgInfo.orgKindName}');
							$("[name='operatorName']").val('${trade.operatorName}');
							$("[name='busStatus']").val('${trade.busStatus}');
							$("[name='buyWay']").val('${trade.buyWay}');
							$("[name='pactId']").val('${trade.pactId}');
							$("[name='proIdStr']").val('${trade.proId}');
							$("[name='remark']").val('${trade.remark}');
						};
						//省份改变，修改城市列表
						$(".provinces").change(function(event) {
							//先移除city列表
							$("#selCity").find("option").remove();
							//省份名
							var selPro = $(this).val();
							//遍历jsonAry
							for (var i = 0; i < jsonAry.length; i++) {
								//遍历json对象
								for (var key in jsonAry[i]) {
									if (key == selPro) {
										cityAry = jsonAry[i][key];
										for (var i = 0; i < cityAry.length; i++) {
											$('#selCity').append("<option>"+ cityAry[i]+ "</option>");
										};
										return;
									};
								};
							};
							
						});
						$("[name='name']").blur(function() {
							if ($(this).val() == '') {
								$("#nameSpan").html("机构名称不能为空");
								$("#nameSpan").css('color', 'red');
							} else {
								$("#nameSpan").html("");
							}

						});
						$("[name='address']").blur(function() {
							if ($(this).val() == '') {
								$("#addressSpan").html("地址不能为空");
								$("#addressSpan").css('color', 'red');
							} else {
								$("#addressSpan").html("");
							}
						});
						$("[name='tel']").blur(function() {
							if ($(this).val() == '') {
								$("#telSpan").html("电话不能为空");
								$("#telSpan").css('color', 'red');
							} else {
								$("#telSpan").html("");
							}
						});
						$(".redStar").change(function() {
							$("#submitbt").attr('disabled', false);
							$(".redStar").each(function() {
								if ($(this).val() == "") {
									$("#submitbt").attr('disabled', true);
								}
							});
						});
						$("[name='contactName']").click(function() {
							$.ajax({
								type : 'post',
								url : 'getContactId',
								data : "contactName=" + $(this).val(),
								success : function(data) {
									$("[name='contactIdStr']").val(data);
								}
							});
						});
						$("[name='operatorName']").click(function() {
							$.ajax({
								type : 'post',
								url : 'getOperatorId',
								data : "operatorName=" + $(this).val(),
								success : function(data) {
									$("[name='operatorIdStr']").val(data);
								}
							});
						});
						$("#submitbt").click(function() {
									if ('${orgInfo}' == '') {
										if (confirm("确认添加？'${orgInfo}'")) {
											$("#basic_validate").attr("action",
													"addOrgAction");
											$("#basic_validate").submit();
										}
									} else {
										if (confirm("确认修改？")) {
											$("#basic_validate").attr("action",
													"updateOrgAction");
											$("#basic_validate").submit();
										}
									}
						});
					});
</script>
</head>
<body>
	<#include "menu.ftl">
	<div id="content">
		<div id="content-header">
			<h1 id="orgH1">添加机构</h1>
			<div class="btn-group">
				<a class="btn btn-large tip-bottom" title="Manage Files"><i
					class="icon-file"></i></a> <a class="btn btn-large tip-bottom"
					title="Manage Users"><i class="icon-user"></i></a> <a
					class="btn btn-large tip-bottom" title="Manage Comments"><i
					class="icon-comment"></i><span class="label label-important">5</span></a>
				<a class="btn btn-large tip-bottom" title="Manage Orders"><i
					class="icon-shopping-cart"></i></a>
			</div>
		</div>
		<div id="breadcrumb">
			<a href="index.html" title="Go to Home" class="tip-bottom"><i
				class="icon-home"></i> Home</a> <a href="#">Form elements</a> <a
				href="#" class="current">Validation</a>
		</div>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<div class="widget-box">
						<div class="widget-title">
							<span class="icon"> <i class="icon-align-justify"></i>
							</span>
							<h5>Rest of elements...</h5>
						</div>
						<div class="widget-content nopadding">
							<form class="form-horizontal" method="post" action="addOrg"
								name="basic_validate" id="basic_validate"
								novalidate="novalidate" />
							<h5>基本信息</h5>
							<hr>
							<div class="control-group">
								<label class="control-label">机构名称：</label>
								<div class="controls">
									<input type="hidden" name="orgIdStr" value=${orgInfo.id }>
									<input type="text" name="name" id="orgName" class="redStar"
										value=${orgInfo.name}> <span id="nameSpan"
										style="color: red;">*</span>
								</div>
							</div>

							<div class="control-group">
								<label class="control-label">省份：</label>
								<div class="controls">
									<select class="provinces" name="province"></select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">城市：</label>
								<div class="controls">
									<select id="selCity" name="city"></select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">机构地址：</label>
								<div class="controls">
									<input type="text" name="address" id="email" class="redStar"
										value=${orgInfo.address}> <span id="addressSpan"
										style="color: red">*</span>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">机构电话：</label>
								<div class="controls">
									<input type="text" name="tel" id="date" class="redStar"
										value=${orgInfo.tel}> <span id="telSpan"
										style="color: red">*</span>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">机构邮编：</label>
								<div class="controls">
									<input type="text" name="post" value=${orgInfo.post}>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">机构网站：</label>
								<div class="controls">
									<input type="text" name="url" value=${orgInfo.url}>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">联系人：</label>
								<div class="controls">
									<select name="contactName" value=${orgInfo.contactName}>
										<#list contactList as contact>
										<option value=${contact.id }>${contact.name }</option>
										</#list>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">重要级别：</label>
								<div class="controls">
									<select name="important" value=${orgInfo.important}>
										<option />一般
										<option />重要
										<option />很重要
										<option />非常重要
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">机构类别：</label>
								<div class="controls">
									<select name="orgKindName" value=${orgInfo.orgKindName}>
										<option value="1"/>省级
										<option value="2"/>市级
									</select>
								</div>
							</div>

							<h5>其他信息</h5>
							<hr>
							<div class="control-group">
								<label class="control-label">经办人：</label>
								<div class="controls">
									<input type="hidden" name="tradeIdStr" value=${trade.id }>
									<select name="operatorName" value=${orgInfo.operatorName}>
										<#list staffList as staff>
										<option value=${staff.id }>${staff.name }</option> </#list>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">采购时间：</label>
								<div class="controls">
									<input type="text" name="dateStr" data-date="12-02-2012"
										data-date-format="dd-mm-yyyy" class="datepicker"
										value=${trade.buyDateStr}>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">商机状态：</label>
								<div class="controls">
									<select name="busStatus" value=${trade.busStatus}>
										<option />一般
										<option />重要
										<option />很重要
										<option />非常重要
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">采购途径：</label>
								<div class="controls">
									<select name="buyWay" value=${trade.buyWay}>
										<option />直接采购
										<option />招标采购
										<option />代理采购
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">合同编号：</label>
								<div class="controls">
									<select name="pactId" value=${trade.pactId}> <#list
										pactList as pact>
										<option>${pact.id }</option> </#list>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">产品编号：</label>
								<div class="controls">
									<select name="proIdStr" value=${trade.proId}> <#list
										proList as pro>
										<option>${pro.id }</option> </#list>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">跟进状态：</label>
								<div class="controls">
									<select name="followStatus" value=${trade.followStatus}>
										<option />初访
										<option />意向
										<option />潜在
										<option />报价
										<option />成交
										<option />暂时搁置
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">备注：</label>
								<div class="controls">
									<textarea name="remark"></textarea>
								</div>
							</div>
							<div class="form-actions">
								<input type="button" id="submitbt" value="提交"
									class="btn btn-primary" />
							</div>
							</form>

						</div>
					</div>
				</div>
			</div>
			<div class="row-fluid">
				<div id="footer" class="span12">
					2012 &copy; Unicorn Admin. Brought to you by <a
						href="https://wrapbootstrap.com/user/diablo9983">diablo9983</a>
				</div>
			</div>
		</div>
	</div>



	<script src="/static/js/jquery.min.js"></script>
	<script src="/static/js/jquery.ui.custom.js"></script>
	<script src="/static/js/bootstrap.min.js"></script>
	<script src="/static/js/bootstrap-colorpicker.js"></script>
	<script src="/static/js/bootstrap-datepicker.js"></script>
	<script src="/static/js/jquery.uniform.js"></script>
	<script src="/static/js/select2.min.js"></script>
	<script src="/static/js/unicorn.js"></script>
	<script src="/static/js/unicorn.form_common.js"></script>
</body>
</html>
